﻿@model IEnumerable<DietPlanning.Models.Dish>
@{
    ViewBag.Title = "FavoriteDish";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm())
{   @Html.ValidationSummary(true)
    <fieldset>
        <div class="editor-label">
            @Html.Label("Tên món ăn")
        </div>
        <div class="editor-field;left">
            @Html.TextBox("txtDishName");
        </div>
        <p>
            <input type="submit" value="Tìm kiếm" />
        </p>
    </fieldset>
}
@if (!Request["txtDishName"].IsEmpty())
{
    var resultDish = Model.Where(o => o.DishName.ToLower().Contains(Request["txtDishName"].ToLower())).ToList();
    <table>
        @for (int i = 0; i < resultDish.Count(); i++)
        {
            DietPlanning.Models.Dish item = resultDish.ElementAt(i);
            if (i % 5 == 0)
            {
            <tr>
            </tr>
            <td>
                <div>
                    <img src="/Images/Dish/@item.ImageURL/"  alt="" height="160px" width="200px" />
                    <br />
                    @Html.DisplayFor(modelItem => item.DishName)
                    <br />
                    Điểm Đánh giá: @Html.DisplayFor(modelItem => item.AverageRate)/10
                </div>
            </td>

            }
            else
            {
            <td>
                <div>
                    <img src="/Images/Dish/@item.ImageURL/"  alt="" height="160px" width="200px"  />
                    <br />
                    @Html.DisplayFor(modelItem => item.DishName)
                    <br />
                    Đánh giá: @Html.DisplayFor(modelItem => item.AverageRate)/10
                </div>
            </td>
            }

        }
    </table>
}
<h3>
    Các món ăn được yêu thích
</h3>
<table>
    @{ 
        var favoriteDish = Model.OrderByDescending(o => o.AverageRate).Take(10).ToList();
        for (int i = 0; i < favoriteDish.Count(); i++)
        {
            DietPlanning.Models.Dish item = favoriteDish.ElementAt(i);
            if (i % 5 == 0)
            {
        <tr>
        </tr>
        <td>
            <div>
                <img src="/Images/Dish/@item.ImageURL/"  alt="" height="160px" width="200px" />
                <br />
                @Html.DisplayFor(modelItem => item.DishName)
                <br />
                Điểm Đánh giá: @Html.DisplayFor(modelItem => item.AverageRate)/10
            </div>
        </td>

            }
            else
            {
        <td>
            <div>
                <img src="/Images/Dish/@item.ImageURL/"  alt="" height="160px" width="200px"  />
                <br />
                @Html.DisplayFor(modelItem => item.DishName)
                <br />
                Đánh giá: @Html.DisplayFor(modelItem => item.AverageRate)/10
            </div>
        </td>
            }

        }
    }
</table>
<h3>
    Các món ăn được xem nhiều
</h3>
<table>
    @{
        var highViewDish = Model.OrderByDescending(o => o.CountView).Take(10).ToList();
        for (int i = 0; i < highViewDish.Count(); i++)
        {
            DietPlanning.Models.Dish item = highViewDish.ElementAt(i);
            if (i % 5 == 0)
            {
        <tr>
        </tr>
        <td>
            <div>
                <img src="/Images/Dish/@item.ImageURL/"  alt="" height="160px" width="200px" />
                <br />
                @Html.DisplayFor(modelItem => item.DishName)
                <br />
                Điểm Đánh giá: @Html.DisplayFor(modelItem => item.AverageRate)/10
            </div>
        </td>

            }
            else
            {
        <td>
            <div>
                <img src="/Images/Dish/@item.ImageURL/"  alt="" height="160px" width="200px"  />
                <br />
                @Html.DisplayFor(modelItem => item.DishName)
                <br />
                Đánh giá: @Html.DisplayFor(modelItem => item.AverageRate)/10
            </div>
        </td>
            }

        }
    }
</table>
